// app.js
App({
  onLaunch() {
    wx.cloud.init({
      env: 'env-7g9v3jl6ff2c202e',
      traceUser: true,
    });
    //重写原型 toLocaleString
    Date.prototype.toLocaleString = function () {
      return this.getFullYear() + "-" + [(this.getMonth() + 1) < 10 ? '0' + (this.getMonth() + 1) : (this.getMonth() + 1)] + "-" + [this.getDate() < 10 ? '0' + this.getDate() : this.getDate()] + " " + [this.getHours() < 10 ? '0' + this.getHours() : this.getHours()] + ":" + [this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes()] + ":" + [this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()];
    };
    //获取openid
    this.getopenid();
    this.getlogindata();
  },

  getlogindata() {
    //获取用户数据
    let openid = wx.getStorageSync('openid');
    wx.cloud.callFunction({
      name: 'daisho_list', data: {
        type: 'get_code',
        openid: openid,
      }
    }).then(res => {
      if (res.result.data.length != 0) {
        wx.setStorageSync('userinfo_inf', res.result.data[0]);
      } else {
        wx.setStorageSync('userinfo_inf', '');
      }
    })
  },


  getopenid() {
    let openid = wx.getStorageSync('openid');
    if (openid == '') {
      wx.cloud.callFunction({ name: 'getopenid', data: { type: 'getopenid' } }).then(res => {
        wx.setStorageSync('openid', res.result.openid);
      }).catch(res => {
        wx.showToast({
          title: '获取openid失败请退出后重新进入程序！',
          icon: 'none'
        })
      })
    }
  },
  globalData: {
    userInfo: null,
    rider_inf: null,
    loop_data: null,
    money: null,
    give_String: null,
  }
})
